<template>
  <div class="merchant-details">
    <el-drawer :modal-append-to-body="false" :append-to-body="true" title="绑定成员" size="65%" class="box-drawer"
      :with-header="false" :visible.sync="drawerLoading" :show-close="true" @close="cloneDrawer">
      <!-- 头部-->
      <div style="position: relative">
        <div class="drawerTitle">
          <span>绑定成员</span>
          <div class="close" @click="cloneDrawer">
            <i class="el-icon-close" style="font-size: 24px;" />
          </div>
        </div>
      </div>
      <div class="container-module">
        <el-form :inline="true" class="search-form" label-position="right" label-width="60px">
          <el-row style="display: flex">
            <span style="line-height: 43px;margin-right: 20px;">查询用户</span>
            <div style="flex: 1;">
             <el-form-item class="search-form-item" label="用户名称" style="margin: 5px 0">
                <el-input clearable placeholder="请输入用户名称" v-model="searchForm.params.nickname" class="input-with-select">
                </el-input>
              </el-form-item>
              <el-form-item class="search-form-item" label="手机号" style="margin: 5px 0">
                <el-input clearable placeholder="请输入手机号" v-model="searchForm.params.mobile" class="input-with-select">
                </el-input>
              </el-form-item>
              <el-form-item class="search-form-item" label="用户ID" style="margin: 5px 0" v-if="searchDisplay">
                <el-input clearable placeholder="请输入用户ID" v-model="searchForm.params.user_id" class="input-with-select">
                </el-input>
              </el-form-item>
            </div>
            <div style="padding: 5px 0">
              <el-form-item>
                <el-button size="small" type="primary" icon="el-icon-search" @click="getinventorylist">查询</el-button>
                <el-button size="small" type="primary" icon="el-icon-refresh" @click="resetting">重置</el-button>
                <!-- <el-button v-if="!searchDisplay" type="warning" icon="el-icon-caret-bottom"
                  @click="searchDisplay = true">展开</el-button>
                <el-button v-else type="warning" icon="el-icon-caret-top" @click="searchDisplay = false">收起</el-button> -->
              </el-form-item>
            </div>
          </el-row>
        </el-form>
      </div>
      <el-divider></el-divider>
      <div style="padding: 0 30px">
            <span style="line-height: 43px;margin-right: 20px;">查询结果</span>
        <el-row :gutter="20">
          <el-col class="new_table_card">
            <el-table v-loading="loading" highlight-current-row :data="inventorylist" :header-cell-style="{
                'background-color': '#f3f8fe',
                color: '#606266',
                height: '50px',
              }" style="width: 100%" height="100%">
              <el-table-column
                align="center"
                width="200"
                prop="nickname"
                label="用户名称"
              >
              </el-table-column>
              <el-table-column
                align="center"
                width="200"
                prop="mobile"
                label="手机号"
              >
              </el-table-column>
              <el-table-column
                align="center"
                width="200"
                prop="id"
                label="用户ID"
              >
              </el-table-column>
              <el-table-column
                align="center"
                prop="id"
                label="指定分组"
              >
              <template slot-scope="scope">
                <el-select clearable v-model="scope.row.market_group_id" placeholder="请选择分组">
                  <el-option v-for="item in groupings" :key="item.id" :label="item.name" :value="item.id">
                  </el-option>
                </el-select>
              </template>
              </el-table-column>
              <el-table-column fixed="right" prop="address" label="操作" align="center" width="180px">
                <template slot-scope="scope">
                  <el-button type="text" size="small" @click="userbind(scope.row)">
                    绑定
                  </el-button>
                </template>
              </el-table-column>
            </el-table></el-col>
          <el-col>
            <pagination v-show="total > 0" :total="total" :page.sync="searchForm.page" :limit.sync="searchForm.count"
              @pagination="getinventorylist" />
          </el-col>
        </el-row>
      </div>
    </el-drawer>
  </div>
</template>
<script>

  import {
    grounplist,
    manageradde,
    userListNotJoin

  } from "@/api/manager/index";
  export default {
    name: 'bindmember',
    components: {},
    data() {
      return {
        operationsid:'',
        groupings:[],//fenzu
        level:'',
        searchDisplay: false, //搜索弹起隐藏
        loading: false,
        searchForm: {
          params:{
            user_id: "", //根据成员用户ID查询
            nickname: "", //根据用户姓名查询
            mobile: "" //根据用户电话查询
          },
          page: 1,
          count: 10,
          
        },
        total: 0,
        drawerLoading: false,
        inventorylist: [],
        searchgrounpForm:{
          page: 1,
          count: 30,
          params:{
            market_manager_id:''
          }
        }
      }
    },
    methods: {
      groupinglist() {
        grounplist(this.searchgrounpForm).then((res) => {
          this.groupings = res.data.list
        })
      },
      //绑定
      userbind(row) {
        if(!row.market_group_id){
          this.$messages.error('请选择分组');
          return
        }
        let param = {
          market_group_id:row.market_group_id,
          user_id:row.id
        }
        manageradde(param).then((res) => {
          if (res.code !== 200 || res.status !== 1) {
            this.$messages.error(res.msg);
            return;
          }
          this.$messages.success(res.msg);
          this.getinventorylist()
        })
      },
      //列表
      getinventorylist() {
        this.loading = true
        userListNotJoin(this.searchForm).then((res) => {
          this.loading = false
          this.inventorylist = res.data.list
          this.total = res.data.total
        })
      },
      //重置
      resetting() {
        this.searchForm = {
          params:{
            user_id: "", //根据成员用户ID查询
            nickname: "", //根据用户姓名查询
            mobile: "" //根据用户电话查询
          },
          page: 1,
          count: 10,
        }

        this.getinventorylist();
      },
      //刷新
      refresh() {
        this.searchForm.page = 1
        this.searchForm.count = 10
        this.getinventorylist();
      },
      //接收父组件传的值
      open(id) {
        this.operationsid = id
        this.drawerLoading = true
        this.loading = true
        this.searchgrounpForm.params.market_manager_id = id
        this.groupinglist()
        userListNotJoin(this.searchForm).then((res) => {
          this.loading = false
          this.inventorylist = res.data.list
          this.total = res.data.total
        })
      },
      //关闭详情抽屉
      cloneDrawer() {
        this.drawerLoading = false
        setTimeout(() => {
            this.$parent.resetting();
        }, 500);
      },
    }
  }
</script>
<style scoped>
  .el-divider--horizontal {
    margin: 2px 0 8px;
  }
</style>
<style lang="scss">
  .container-module {
    padding: 20px 20px 10px 30px;
  }
  .infoDiv {
    margin: 0 auto 16px;
    display: flex;
    border: 1px solid #c6c6c6;
    border-radius: 6px;
    padding: 10px;
    .img {
      width: 80px;
      height: 80px;
      border-radius: 50%;
      background-color: #fff;

    }
    .right {}
    .scenter {
      flex: 1;
      margin-left: 10px;

      h3 {
        line-height: 30px;
        font-weight: 400;
        font-size: 16px;
        padding: 0px 0;
        margin: 0;
      }
    }
  }
  .orderdetail_item {
    display: flex;
    justify-content: start;
    margin-right: 30px;
    p:nth-child(2) {
      color: #000;
      font-weight: 550;
      margin-left: 15px;
    }
  }
  .order_center {
    display: flex;
    align-items: center;
    justify-content: start;
    flex-wrap: wrap;
    padding: 0 2px 0 0;
    font-size: 13px;
    color: #666;
  }
</style>
